package com.cade.agriculturemall.view.home;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.cade.agriculturemall.R;
import com.cade.agriculturemall.base.BaseFragment;
import com.cade.agriculturemall.base.IBasePresenter;
import com.cade.agriculturemall.view.home.promotion.PromotionActivity;
import com.cade.agriculturemall.view.home.search.SearchActivity;
import com.cade.agriculturemall.widget.GlideImageLoader;
import com.cade.agriculturemall.widget.SearchEditText;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lobby on 2017/11/16.
 */

public class HomeFragment extends BaseFragment {
    private Banner mBanner;
    private View get;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int setupLayout() {
        return R.layout.layout_home_fragment;
    }

    @Override
    public void setupView() {
        mBanner = (Banner) getView().findViewById(R.id.home_banner);
        EditText edtSearch = (EditText) getView().findViewById(R.id.home_search_edt);
        edtSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), SearchActivity.class));
            }
        });
        ImageView imgLongBanner = (ImageView) getView().findViewById(R.id.home_long_img_banner);
        ImageView imgPartOne = (ImageView) getView().findViewById(R.id.home_Iv_part_one);
        ImageView imgPartTwo = (ImageView) getView().findViewById(R.id.home_Iv_part_two);
        ImageView imgPartThree = (ImageView) getView().findViewById(R.id.home_Iv_part_three);
        ImageView imgPartFour = (ImageView) getView().findViewById(R.id.home_Iv_part_four);
        Glide.with(getActivity()).load("http://004.sfimg.cn/web/2e04f962/2e04f962f3b11e12bb9e816f7737a74f.jpg")
                .into(imgLongBanner);
        Glide.with(getActivity()).load("http://img04.ttmimg.com/www/images/index/zh_cn/bj/first/d08d41059d004d56d57362b5aba50e0e.jpg")
                .into(imgPartOne);
        Glide.with(getActivity()).load("http://img01.ttmimg.com/www/images/index/zh_cn/bj/first/0b2abb2d3bbf8bbb70b51944ace9944d.jpg")
                .into(imgPartTwo);
        Glide.with(getActivity()).load("http://004.sfimg.cn/web/2e04f962/2e04f962f3b11e12bb9e816f7737a74f.jpg")
                .into(imgPartThree);
        Glide.with(getActivity()).load("http://004.sfimg.cn/web/2e04f962/2e04f962f3b11e12bb9e816f7737a74f.jpg")
                .into(imgPartFour);
        mBanner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                startActivity(new Intent(getActivity(), PromotionActivity.class));
            }
        });
        imgPartOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), PromotionActivity.class));
            }
        });
    }

    @Override
    public void setupEvent() {
        //设置banner样式
        mBanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE);
        //设置图片加载器
        mBanner.setImageLoader(new GlideImageLoader());
        List<String> list = new ArrayList<>();
        list.add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3784449880,1879286739&fm=27&gp=0.jpg");
        list.add("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=4173575611,149534594&fm=27&gp=0.jpg");
        list.add("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3694966705,212540604&fm=27&gp=0.jpg");

        list.add("http://003.sfimg.cn/web//4f27c27a/4f27c27a6116fcd83401ec0ffed04dc7.jpg");
        list.add("http://001.sfimg.cn/web//76f510ab/76f510ab67676e49f1c2006f42463436.jpg");
        list.add("http://003.sfimg.cn/web//0e6ec0a1/0e6ec0a16aedc8628ad018b88d10b398.jpg");
        list.add("http://img04.ttmimg.com/www/images/sale/zh_cn/bj/150546554446/img_02.jpg");
        //设置图片集合
        mBanner.setImages(list);
        //设置mBanner动画效果
        mBanner.setBannerAnimation(Transformer.DepthPage);
        //设置标题集合（当mBanner样式有显示title时）

        List<String> listTitle = new ArrayList<>();
        listTitle.add("11.11狂欢");
        listTitle.add("鲜果盛世");
        listTitle.add("锋芒毕露");
        listTitle.add("牛牛盛会");
        listTitle.add("严选鲜虾上市");
        listTitle.add("冬令滋补季");
        listTitle.add("鲜熟果蓝开采");
        mBanner.setBannerTitles(listTitle);
        //设置自动轮播，默认为true
        mBanner.isAutoPlay(true);
        //设置轮播时间
        mBanner.setDelayTime(1500);
        //设置指示器位置（当mBanner模式中有指示器时）
        mBanner.setIndicatorGravity(BannerConfig.CENTER);
        //mBanner设置方法全部调用完毕时最后调用
        mBanner.start();
    }

    @Override
    public void setupData() {

    }

    @Override
    public IBasePresenter setupPresenter() {
        return null;
    }
}
